/*
   Copyright 2009 Bloo. All Rights Reserved.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
package org.youtensils.www.client.widgets.dialogs;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * A dialog box alerting the user that the Java applet was not granted sufficient permissions to run.
 * @author Bobby Soares
 */
public class JavaSandboxDialog extends Dialog {
	private VerticalPanel contentPane;
	private HorizontalPanel buttonPane;
	
	/**
	 *  A constructor.
	 */
	public JavaSandboxDialog() {
		super("Java Applet Not Running", true);
		this.contentPane = new VerticalPanel();
		this.contentPane.setWidth("500px");
		this.buttonPane = new HorizontalPanel();
		this.contentPane.add(new HTML("The Java applet was not allowed to execute. You will need to " +
					"click refresh or restart your browser and allow the applet to run when prompted."));
		Button refresh = new Button("Refresh Page");
		Button ignore = new Button("Ok");
		refresh.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				JavaSandboxDialog.this.hide();
				Window.Location.reload();
			}
		});
		ignore.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				JavaSandboxDialog.this.hide();
			}
		});
		closeButton.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				JavaSandboxDialog.this.hide();
			}
		});
		this.buttonPane.add(refresh);
		this.buttonPane.add(ignore);
		this.buttonPane.setStylePrimaryName("gwt-Dialog-ButtonPane");
		this.contentPane.add(buttonPane);
		setContentWidget(this.contentPane);
	}
}